#include <iostream>
#include <cmath>
#include <vector>
#include <numeric>

using namespace std;

static bool prime(uint64_t n) {
    if (n < 2) return false;
    if (n == 2) return true;
    if (n % 2 == 0) return false;
    for (uint64_t i = 3; i * i <= n; i += 2) {
        if (n % i == 0)
            return false;
    }
    return true;
}

static bool palindrome(const vector<unsigned>& v) {
    for (int i = 0, j = v.size() - 1; i < j; ++i, --j) {
        if (v[i] != v[j])
            return false;
    }
    return true;
}

int main() {
    vector<uint64_t> v;
    for (uint64_t i = 13; v.size() < 50; i += 2) {
        if (!prime(i))
            continue;

        uint64_t n = i * i;
        vector<unsigned> a;
        while (n) {
            a.push_back(n % 10);
            n /= 10;
        }
        if (palindrome(a))
            continue;

        uint64_t m = 0;
        for (auto e : a)
            m = 10 * m + e;
        uint64_t k = static_cast<uint64_t>(1e-3 + sqrt(static_cast<double>(m)));
        if (k * k == m && prime(k)) {
            v.push_back(i * i);
            cout << v.back() << " : " << k * k << endl;
        }
    }
    cout << accumulate(v.begin(), v.end(), 0ULL) << endl;
}